﻿using System.Collections.Generic;
using System.Threading.Tasks;
using B.MESUI.Login.A_Public.Constants;
using B.MESUI.Login.A_Public.Helpers;
using B.MESUI.Login.ProdManagement.DTO;
using Newtonsoft.Json;

namespace B.MESUI.Login.ProdManagement.Services
{
    /// <summary>
    /// 产线管理服务类
    /// </summary>
    public static class ProjectLineService
    {
        /// <summary>
        /// 获取产线列表。
        /// </summary>
        /// <returns>产线列表</returns>
        public static async Task<List<ProductionLine>> GetProductionLinesAsync()
        {
            try
            {
                var url = HttpClientHelper.GetProjectLineUrl(ApiEndpoints.ProjectLine.GetProductionLine);
                var response = await HttpClientHelper.GetAsync(url);
                var result = JsonConvert.DeserializeObject<ProductionLineResult>(response);
                return result?.resultData ?? new List<ProductionLine>();
            }
            catch
            {
                return new List<ProductionLine>();
            }
        }
    }
}